<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" %>
<%@ page import="support.*, java.util.*" %>
    
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Citizenship</title>
<link href="main.css" rel="stylesheet" type="text/css">

</head>
<body>
<%
	// Get name from HTTP request
	String first = request.getParameter("first_name");
	String last = request.getParameter("last_name");
	String mid = request.getParameter("middle_name");

	Applicant a = new Applicant();
	a.setName(new Name(first, last, mid));
	
	// Store applicant in session
	session.setAttribute("applicant", a);
	
	// Get countries from database
	DatabaseAccessObject dao = new DatabaseAccessObject();
	LinkedList<Country> countries = dao.getCountries();

%>
<jsp:include page="information.jsp"></jsp:include>

<h1>Please choose your citizenship</h1>
<table class="multicolumn">
	<tr>
		<% 
		int cols = 3;
		int itemsPerCol = countries.size() / cols;
		if (countries.size() % cols != 0) itemsPerCol += 1;
		
		for(int i=0; i<countries.size(); i++){
			if (i % itemsPerCol == 0)  out.println("<td>");
			out.println("<a class=\"list\" href=\"residence.jsp?citizenshipID=" + countries.get(i).getId() + 
					              "&citizenship=" + countries.get(i).getName() + "\" >" + 
			                      countries.get(i).getName() + "</a>");
			if (i % itemsPerCol == itemsPerCol-1 || i==countries.size() -1 )  out.println("</td>");
		};
		%>
	</tr>
</table>

</body>
</html>